import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { clueVO, clueForm, clueQuery } from '@/api/goods/clue/types';
import { AnyFn } from '@vueuse/core';

/**
 * 查询线索列表
 * @param query
 * @returns {*}
 */

export const listClue = (query?: clueQuery): AxiosPromise<clueVO[]> => {
  return request({
    url: '/order/clue/list',
    method: 'get',
    params: query
  });
};
/**
 * 查询线索统计
 * @param query
 * @returns {*}
 */
export const listcount = (query?: clueQuery): AxiosPromise<any> => {
  return request({
    url: '/order/clue/listCount',
    method: 'get',
    params: query
  });
};

/**
 * 查询线索详细
 * @param id
 */
export const getClue = (id: string | number): AxiosPromise<clueVO> => {
  return request({
    url: '/order/clue/' + id,
    method: 'get'
  });
};

/**
 * 查询线索详细
 */
export const getClueAllList = (): AxiosPromise<clueVO> => {
  return request({
    url: '/order/clue/allList',
    method: 'get'
  });
};

/**
 * 查询线索编号
 */
export const getClueCode = (): AxiosPromise<clueVO> => {
  return request({
    url: '/order/clue/getClueNumber',
    method: 'get'
  });
};

/**
 * 新增线索
 * @param data
 */
export const addClue = (data: clueForm) => {
  return request({
    url: '/order/clue',
    method: 'post',
    data: data
  });
};
/**
 * 新增线索
 * @param data
 */
export const updatePersonAssigner = (data: clueForm) => {
  return request({
    url: '/order/clue/updatePersonAssigner',
    method: 'post',
    data: data
  });
};

/**
 * 修改线索
 * @param data
 */
export const updateClue = (data: clueForm) => {
  return request({
    url: '/order/clue',
    method: 'put',
    data: data
  });
};

/**
 * 删除线索
 * @param id
 */
export const delClue = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/clue/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param clueId 客户端id
 * @param status 状态
 */
export function changeStatus(clueId: string, status: string) {
  const data = {
    clueId,
    status
  };
  return request({
    url: '/order/clue/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list:listClue,
  get:getClue,
  add:addClue,
  update:updateClue,
  del:delClue,
  getClueAllList:getClueAllList
}